<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" placeholder="请输入手机号">
    <button>发送</button>
    <script>
        //  点击发生后显示还剩下几秒
        var ipt = document.querySelector('input')
        var btn = document.querySelector('button')
        var timer = 3
        btn.addEventListener('click', function () {
            function times() {
                if (timer == 0) {
                    btn.disabled = false
                    btn.innerHTML = '发送'
                    timer = 3
                    clearInterval(clear)
                } else {
                    btn.disabled = true
                    btn.innerHTML = '还剩下' + timer + '秒'
                    timer--
                }
            }
            times()
            var clear = setInterval(times, 1000)
        })

































        // var but = document.querySelector('button')
        // var time = 3;
        // but.addEventListener('click', function () {
        //     var clears = setInterval(function () {
        //         if (time == 0) {
        //             but.disabled = false
        //             but.innerHTML = '发送'
        //             //必须复原time值 不然定时器再次开始时 time值会为0 点击事件发生后会直接执行iftime=0的语句 这样逻辑顺序就错了
        //             time = 3
        //             clearInterval(clears)

        //         } else {
        //             but.disabled = true
        //             but.innerHTML = '还剩下' + time + '秒'
        //             time--
        //         }
        //     }, 1000)
        // })

    </script>
</body>

</html>